<?php

namespace App\Models\Traits;

use Brick\Math\RoundingMode;
use Illuminate\Support\Facades\DB;

trait ProductTrait
{
	public function syncAttribute()
	{
		$originalAttrGroupId = $this->getOriginal('attribute_group_id');
		$currentAttrGroupId = $this->attribute_group_id;
		if (empty($currentAttrGroupId) or ($originalAttrGroupId != $currentAttrGroupId)) {
			DB::transaction(function () {
				$this->skus()->update(['attr_value' => null, 'attr_value_index' => null]);
				$this->attributeValues()->delete();
			});
		}
	}
}
